package com.holike.crm.activity.analyze;

import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.holike.crm.R;
import com.holike.crm.base.BaseActivity;
import com.holike.crm.bean.CupboardBean;
import com.holike.crm.bean.PerformanceBean;
import com.holike.crm.dialog.LoadingTipDialog;
import com.holike.crm.fragment.analyze.PerformanceFragment;
import com.holike.crm.fragment.analyze.PerformancePersonalFragment;
import com.holike.crm.presenter.fragment.PerformancePresenter;
import com.holike.crm.util.Constants;
import com.holike.crm.view.fragment.PerformanceView;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 业绩报表
 */
public class PerformanceActivity extends BaseActivity<PerformancePresenter, PerformanceView> implements PerformanceView {
    @Override
    protected boolean isFullscreen() {
        return Build.VERSION.SDK_INT < Build.VERSION_CODES.M;
    }

    @Override
    protected PerformancePresenter attachPresenter() {
        return new PerformancePresenter();
    }

    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_performance;
    }

    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        setTitle(getString(R.string.report_item8_title));
        getData();
    }

    @Override
    protected Dialog getLoadingDialog() {
        return new LoadingTipDialog(this);
    }

    @Override
    public void getData() {
        showLoading();
        mPresenter.getData(null, null, null);
    }

    /**
     * 获取业绩数据成功
     */
    @Override
    public void getDataSuccess(PerformanceBean performanceBean) {
        dismissLoading();
        Map<String, Serializable> params = new HashMap<>();
        params.put(Constants.PERFORMANCE_BEAN, performanceBean);
        if (TextUtils.equals(performanceBean.getIsDealer(), "1")) {
            setTranslucentStatus();
            startFragment(params, new PerformancePersonalFragment(), false);
        } else {
            startFragment(params, new PerformanceFragment(), false);
        }
    }


    /**
     * 获取橱柜数据成功
     */
    @Override
    public void getCupboardDataSuccess(CupboardBean bean) {
        dismissLoading();
    }

    /**
     * 获取数据失败
     */
    @Override
    public void getDataFailed(String failed) {
        dismissLoading();
        showShortToast(failed);
    }

}
